//
//  DepoistTypeListItemCell.swift
//  d11
//
//  Created by peale on 2018/10/20.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit

class DepoistTypeListItemCell: UITableViewCell {
    var bgImgView : UIImageView?
    var iconImgView : UIImageView?
    var tagImageView : UIImageView?
    var titleLabel : UILabel?
    var tagName : UILabel?
    var arrowImgView : UIImageView?
    var lineView : UIView?
    var tagView : UIView?
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setUpUI() -> Void {
        self.backgroundColor  = UIColor.clear
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        // self.contentView!.backgroundColor  = UIColor.clear
        self.bgImgView = UIImageView.init()
        self.bgImgView?.image = imageNamed("icon_my_cell_item")?.resizableImage(withCapInsets: UIEdgeInsets(top: 5, left: 30, bottom: 5, right: 30),
                                                                                 resizingMode: .stretch) //左右15像素的部分不变，中间部分来拉伸
        self.contentView.addSubview(bgImgView!);
        self.bgImgView?.snp.makeConstraints{(make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(60)
            make.centerX.equalTo(self.contentView)
        };
        self.tagView = UIView.init()
        self.bgImgView?.addSubview(tagView!)
        self.tagView?.snp.makeConstraints{(make) in
            make.width.equalTo(70)
            make.height.equalTo(22)
            make.top.equalToSuperview().offset(5)
            make.right.equalToSuperview().offset(-5)
        }
        self.tagImageView = UIImageView.init()
        self.tagImageView?.image = imageNamed("deposi_tag")?.resizableImage(withCapInsets: UIEdgeInsets(top: 5, left: 30, bottom: 5, right: 30),
        resizingMode: .stretch)
        tagView?.addSubview(self.tagImageView!)
        self.tagImageView?.snp.makeConstraints{(make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
//            make.top.equalToSuperview().offset(5)
//            make.right.equalToSuperview().offset(-5)
        }
       self.tagName = UILabel.init()
       self.tagName?.text = "限时存款"
       self.tagName?.textColor = HexRGBAlpha(0xffffff, 1)
       self.tagName?.font = UIFont.systemFont(ofSize: 12)
        self.tagName?.textAlignment = NSTextAlignment.left
       self.tagView?.addSubview(self.tagName!)
       self.tagName?.snp.makeConstraints{(make) in
//             make.left.equalTo((self.tagImageView?.snp.right)!)
//             make.right.equalTo((self.tagImageView?.snp.right)!)
//             make.width.equalToSuperview()
        make.top.equalToSuperview().offset(2)
//            make.left.equalToSuperview()
//            make.height.equalToSuperview()
            make.centerX.equalToSuperview()
        }
        tagView?.isHidden = true
        self.iconImgView = UIImageView.init()
    //    self.iconImgView?.image = imageNamed("icon_depoist_type_list_online_banking")
        self.bgImgView?.addSubview(self.iconImgView!)
        self.iconImgView?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(12)
            make.width.equalTo(25)
            make.height.equalTo(25)
            make.centerY.equalTo(self.bgImgView!)
        }
        self.titleLabel = UILabel.init()
   //     self.titleLabel?.text = "网银"
        self.titleLabel?.textColor = HexRGBAlpha(0x333333, 1)
        self.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        self.titleLabel?.textAlignment = NSTextAlignment.left
        self.bgImgView?.addSubview(self.titleLabel!)
        
        self.titleLabel?.snp.makeConstraints{(make) in
            make.left.equalTo((self.iconImgView?.snp.right)!).offset(10)
            make.width.equalToSuperview().offset(-70)
            make.height.equalTo(51)
            make.centerY.equalToSuperview()
        }
        
        self.arrowImgView = UIImageView.init()
        self.arrowImgView?.image = imageNamed("icon_depoist_cell_arrow")
        self.bgImgView?.addSubview(self.arrowImgView!)
        
        self.arrowImgView?.snp.makeConstraints{(make) in
            make.right.equalToSuperview().offset(-12)
            make.width.equalTo(9)
            make.centerY.equalTo(self.bgImgView!)
            make.height.equalTo(15)
        }
        
        
        self.lineView = UIView.init()
        self.lineView?.backgroundColor = HexRGBAlpha(0xF3F3F3, 1)
         self.lineView?.isHidden = true
        self.bgImgView?.addSubview(self.lineView!)
        
        self.lineView?.snp.makeConstraints{(make) in
            make.centerX.equalToSuperview()
            make.width.equalToSuperview().offset(-10)
            make.height.equalTo(0.7)
            make.bottom.equalToSuperview()
        }
    }
    
    func setData(dict:[String:Any]?) -> Void {
        if  dict != nil {
            let infoDict :[String:Any] = dict?["showInfo"] as? [String : Any] ?? [String:Any]()
            let optionid = infoDict["optionid"] as! String
            let dataDict = dict?[optionid] as? [String:Any] ?? [String:Any]()
            var rangeLimit = dataDict["rangeLimit"] as? String ?? ""
            if(rangeLimit == ""){
                let arrays = dict?[optionid] as? [[String:Any]] ?? [[String:Any]]()
                let temp = arrays[0] as? [String:Any] ?? [String:Any]()
                for (key, value) in temp {
                    if(key != "showInfo"){
                        let values = temp[key] as? [String:Any] ?? [String:Any]()
                        rangeLimit = values["rangeLimit"] as? String ?? ""
                        break
                    }
                }
            }
            var tagNames : String = infoDict["tag_name"] as? String ?? ""
                       print("Deposit=====\(rangeLimit)===\(dict)===\(tagNames)")
                       if(tagNames != ""){
                           tagView?.isHidden = false
                           tagName?.text = tagNames
                       }else{
                           tagView?.isHidden = true
                       }
            print("Deposit=====\(rangeLimit)===\(dict)===\(tagNames)")
            let money = rangeLimit.components(separatedBy: ",")
            let min = money[0]
            let max = money[1]
            let showName = infoDict["show_name"] as? String ?? ""
            let attributedStrM : NSMutableAttributedString = NSMutableAttributedString()
            let nameAttrs : [ NSAttributedString.Key:Any] = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 15)]
            let name = NSAttributedString.init(string: showName, attributes: nameAttrs)
            let minAttrs : [ NSAttributedString.Key:Any] = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 12)]
            let minStr = NSAttributedString.init(string: "(最小:\(min),最大:\(max))", attributes: minAttrs)
            attributedStrM.append(name)
            attributedStrM.append(minStr)
            self.titleLabel?.attributedText = attributedStrM
            self.iconImgView?.sd_setImage(with: URL.init(string: infoDict["image_url"] as? String ?? ""), completed: nil)
        }
      
    }
    
}
